home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / ScriptX / Code Samples / autofind / source / grphclab.sx < prev    next >
Encoding:
Text File  |  1996-05-21  |  2.6 KB  |  92 lines  |  [TEXT/ttxt]

  1. --<<<
  2. -- Filename: 
  3. --     grphclab.sx
  4.  
  5. -- Other Files Required:
  6. --     None
  7.  
  8. -- Purpose:  
  9. --     Class definitions for text labels and buttons with graphic backgrounds
  10.  
  11. -- Specialized Classes:  
  12. --     graphicLabel, graphicLabelButton
  13.  
  14. -- Instructions to User: 
  15. --     The graphicLabel specializes the built-in TwoDMultiPresenter class
  16. --     to create a class that combines a textbox with a twoDShape to create a 
  17. --     settable (but not editable) text field over a graphic background.
  18. --     Instance variables:
  19. --     name:            a string, the object's name
  20. --     textField:        a TextPresenter, containing the text displayed over the background.
  21.  
  22. -- Authors:
  23. --      Steve Gano, Dionn M. Stewart
  24.  
  25. in module Autofinder
  26.  
  27. class GraphicLabel (TwoDMultiPresenter)
  28. instance variables
  29.     textField        -- a text presenter
  30. instance methods
  31.     method targetSetter self value -> (
  32.         if (isAKindOf value String) then
  33.         (
  34.             self.textField.target := value
  35.             return value
  36.         )
  37.         else
  38.             nextMethod self value
  39.     )
  40. end
  41.  
  42. -- Create a new graphicLabel with:
  43. --    bkgnd:        twoDshape for the background
  44. --    vmarg, hmarg:    integers, the vertical and horizontal margins
  45. --    fontChanges:    keyed linked list of text attributes to change
  46. method init self {class GraphicLabel} #rest args #key \
  47.     background:(new TwoDshape boundary:(new Rect x2:100 y2:100) fill:undefined) \
  48.     hmarg:(0) \
  49.      vmarg:(0) \
  50.     fontChanges:(new KeyedLinkedList) \
  51.     label:("") ->
  52. (
  53.     -- Derive the boundary of the presenter from the background.
  54.     local bnds := new Rect x2:background.width y2:background.height
  55.     apply nextMethod self target:undefined boundary:bnds args
  56.  
  57.     -- Make the textPresenter
  58.     -- Inset the background bounds by given margins to make text box boundary
  59.     bnds := new Rect x2:(background.width - (2 * hmarg)) \
  60.                                 y2:(background.height - vmarg)
  61.     self.textField := new TextPresenter boundary:bnds target:(label as Text)
  62.  
  63.     -- Set the text box attributes.
  64.     forEachBinding fontChanges (key val arg ->
  65.         setDefaultAttr self.textField key val
  66.     ) undefined
  67.     self.textField.x := hmarg
  68.     self.textField.y := vmarg
  69.     append self background
  70.     prepend self self.textField
  71.     self
  72. )
  73.  
  74. -- The graphicLabelButton class specializes graphicLabel by mixing in
  75. --    the built-in Actuator class, which lets it act like a button.  
  76. -- Instance variables:
  77. --    authorData:        optional data to be passed to the depressAction
  78. class GraphicLabelButton (GraphicLabel, Actuator)
  79. instance variables
  80.     authorData        -- any user defined object
  81. end
  82.  
  83. method init self {class GraphicLabelButton} #rest args \
  84.                     #key authorData:(undefined) ->
  85. (
  86.     apply nextMethod self args
  87.     self.authorData := authorData
  88. )
  89.  
  90. "Compiled grphclab.sx"
  91. -->>>
  92.